//package com.itheima.springbootwebtlias.aspect;
//
//import com.itheima.springbootwebtlias.mapper.EmpLoginLogMapper;
//import com.itheima.springbootwebtlias.pojo.Emp;
//import com.itheima.springbootwebtlias.pojo.EmpLoginLog;
//import com.itheima.springbootwebtlias.pojo.Result;
//import com.itheima.springbootwebtlias.util.JwtUtils;
//import io.jsonwebtoken.Claims;
//import jakarta.servlet.http.HttpServletRequest;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//import java.util.Map;
//
//@Slf4j
////@Aspect
//@Component
//public class EmpLoginLogAspect {
//
//    @Autowired
//    private EmpLoginLogMapper empLoginLogMapper;
//
//   @Around("execution(* com.itheima.springbootwebtlias.controller.LoginController.login(com.itheima.springbootwebtlias.pojo.Emp))")
//    public Object recordEmpLoginLog(ProceedingJoinPoint pjp) throws Throwable{
//       long start = System.currentTimeMillis();
//       Object result = null;
//       try {
//           result = pjp.proceed();
//       }catch (Exception e){
//          result = Result.error(e.getMessage());
//       }finally {
//           long end = System.currentTimeMillis();
//           long costTime = end - start;
//
//           //获取令牌，获取目标方法login登陆结果，从Result中获取令牌
//           Result result2 = (Result) result;
//           Map map = (Map) result2.getData();
//
//           String token = "";
//           if(map != null){
//               token = (String) map.get("token");
//           }
//
//           //获取登陆结果，目标方法ligin登陆结果
//           int code = (Integer) result2.getCode();
//           short isSuccess = (short) code;
//
//           //获取请求参数，通过连接点对象获取目标方法参数列表
//           Emp emp = (Emp) pjp.getArgs()[0];
//
//           //定义操作日志对象，手机操作日志信息
//           EmpLoginLog empLoginLog = new EmpLoginLog();
//
//           empLoginLog.setLoginTime(LocalDateTime.now());
//           empLoginLog.setUsername(emp.getUsername());
//           empLoginLog.setPassword(emp.getPassword());
//           empLoginLog.setIsSuccess(isSuccess);
//           empLoginLog.setJwt(token);
//           empLoginLog.setCostTime(costTime);
//
//           //2.调用操作日志的持久层接口添加日志信息到操作日志中
//           empLoginLogMapper.insert(empLoginLog);
//       }
//       return result;
//
//    }
//
//}
